/*******************************************************************************
 * Copyright (c) 2010 Mikhail Garber.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License (LGPL)
 * which accompanies this distribution
 * 
 * Contributors:
 *     Mikhail Garber - initial API and implementation
 ******************************************************************************/
package plumber.common;

import java.util.Date;

@SuppressWarnings("serial")
/**
 * encapsulates a single work item in the workflow system
 */
public class WorkItem extends WithId implements Comparable<WorkItem>{


	/**
	 * represents status of the corresponding workflow Step
	 * 
	 * AVAILABLE - can be picked up for execution
	 * IN_PROGRESS - currently being executed
	 * FAILED - step failed and no retries are scheduled
	 * TO_RETRY - step failed an retry was schedule
	 * FINAL - last step of successful execution of a Flow
	 * DONE - step executed sucessfully
	 * SUSPENDED - otherwise AVAILABLE step was suspended to pause a Flow
	 * 
	 * @author mgarber
	 *
	 */
	public enum Status {AVAILABLE, IN_PROGRESS, FAILED, TO_RETRY, FINAL, DONE, SUSPENDED}
	
	
	private String flowStepId;
	private String requestId;
	private Status status;
	private String context;
	private Date scheduled = new Date();
	private String flowName;
	private String namespace;
	
	public String getNamespace() {
		return namespace;
	}
	public void setNamespace(String namespace) {
		this.namespace = namespace;
	}
	public String getFlowName() {
		return flowName;
	}
	public void setFlowName(String flowName) {
		this.flowName = flowName;
	}
	public Date getScheduled() {
		return scheduled;
	}
	public void setScheduled(Date scheduled) {
		this.scheduled = scheduled;
	}
	
	public String getContext() {
		return context;
	}
	public void setContext(String context) {
		this.context = context;
	}
	public String getFlowStepId() {
		return flowStepId;
	}
	public void setFlowStepId(String flowStepId) {
		this.flowStepId = flowStepId;
	}
	public String getRequestId() {
		return requestId;
	}
	public void setRequestId(String requestId) {
		this.requestId = requestId;
	}
	public Status getStatus() {
		return status;
	}
	public void setStatus(Status status) {
		this.status = status;
	}
	@Override
	public String toString() {
		
		return super.toString() + "flow: " + this.flowName + " rid:" + this.requestId + " " + 
		", step:" + this.flowStepId + ", status: " + this.status;
	}
	@Override
	public int compareTo(WorkItem o) {
		return this.scheduled.compareTo(o.getScheduled());
	}
	
	
}
